/**
 * class name: itable,
 * copyright: maximus zhang,
 * License: MIT-LICENSE,
 * contact: maximus.zhang@gmail.com,
 * required-js: http://jsease.googlecode.com/svn/trunk/core.js,
 * update: http://jsease.googlecode.com/svn/trunk/itable.js
 * -------
 */
function itable() {
    var A = arguments,
        _ = this;
    _ = ext( _, ext(
        {
        id: 'itable',
        elem: me.body,
        cls: 'itable',
        styl: [80, 160, 240],
        data: [
                [
                'col0',
                'col1',
                'col9'
                ]
            ],
        fn:''
        }, A[0] ) );

    _.uitype = 'itable';

    _.elem = $(_.elem) || me.body;


    _.addRow = function (v) {
        if ( !isArray(v) ) {
            return _;
        }

        for ( var i=0, L=v.length; i<L; i++ ) {
            var tri = elm('tr').setClass('itable-row'+ (i%2)).appendTo( i ? _.tbody : _.thead );
            tri.attr('id', v[i].id);
            if ( i ) {
                tri.onmouseover = function () {
                    //this.style.borderColor = '#45b035';
                return false;
                };
                tri.onmouseout = function () {
                    //this.style.borderColor = '#cde';
                return false;
                };
            }

            /* cells */
            for ( var j=0, K=v[i].length; j<K; j++ ) {
                var tdj = elm('td').setClass('itable-col'+ j).appendTo(tri).html(v[i][j]);
                tdj.style.width = _.styl[j] +'px';
                //tri.insertCell(j);
            }

            if ( typeof _.fn == 'function' ) {
                tri.onclick = function () {
                return _.fn.apply(this, [tri]);
                };
            } else if ( typeof _.fn == 'string' ) {
                tri.attr('onclick', _.fn);
            }

        }

    return _;
    };

    _.init = function () {
        _.$ = elm('div').appendTo(_.elem);
        _.ictrl = elm('div').appendTo(_.$);
        _.ihead = elm('div').setClass('itable-thead').appendTo(_.$);
        //_.ibody = elm('div').setClass('itable-tbody').appendTo(_.$);

        _.table = elm('table').setClass(_.cls).attr('id', _.id).appendTo(_.ihead);
        _.thead = elm('thead').appendTo(_.table);

        //_.btable = elm('table').setClass(_.cls).appendTo(_.ibody);
        _.tbody = elm('tbody').appendTo(_.table);

        _.addRow(_.data);
    return _;
    };

}